package com.cmwa.solution.sys.menu.tag;

import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import com.cmwa.solution.sys.client.Client;
import com.cmwa.solution.sys.client.ClientManager;
import com.cmwa.solution.sys.menu.entity.MenuVo;
import com.cmwa.solution.sys.menu.service.MenuService;
import com.cmwa.solution.utils.spring.ContextHolderUtil;
import com.cmwa.solution.utils.spring.SpringContextUtil;

/**
 * 根据T_SYS_MENU.MCODE，判断是否有权限，以确定是否显示标签内的内容
 * @author ex-zuotc
 *
 */
public class HasPermissionTag extends TagSupport {
	private static final long serialVersionUID = 1L;
	/** 操作按钮ID */
	protected String id;

	public int doStartTag() throws JspException {
		MenuService menuService = SpringContextUtil.getBean(MenuService.class);
		MenuVo menu = menuService.queryMenuByCode(id);
		HttpSession session = ContextHolderUtil.getSession();
		Client client = ClientManager.getInstance().getClient(session.getId());
		if (client != null && menu != null && (client.getButtonMenus() != null || client.getOtherMenus() != null)) {
			if (client.getButtonMenus().containsKey(id) || client.getOtherMenus().containsKey(id)) {
				return EVAL_BODY_INCLUDE;
			}
		}
		return SKIP_BODY;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}
}